import {createSlice} from '@reduxjs/toolkit'

const userSlice = createSlice({
  name: 'counter',
  initialState:{
    count: 10,
    userInfo: {
      name: '小明',
      age:18
    }
  },
  reducers:{
    changeCount(state,{payload}){
      state.count = payload
    }
  }
})
export const {
  changeCount
} = userSlice.actions
export default userSlice.reducer
// 使用demo
// import {useStoreDispatch, useStoreSelector} from "@/store/store";
// import {changeCount} from "@/store/modules/user";
// const dispatch = useStoreDispatch()
// const { user,count } = useStoreSelector((state) => ({
//   user: state.user.userInfo,
//   count: state.user.count
// }))
// function handleChange(){
//   dispatch(changeCount(100))
// }
